<template>
  <view class="null-box" v-if="cart.length === 0">
    <image src="@/static/cat-null.png" mode=""></image>
    <text>亲，没有商品哦，马上去购物吧</text>
  </view>
  <view v-else>
    <!-- 地址区 -->
   <block class="adress-content">
    <my-adress></my-adress>
   </block>
    <!-- 标题区 -->
    <view class="title-box">
      <uni-icons class="shop-icon" type="shop" size="30"></uni-icons>
      <view class="title-text">
        购物车
      </view>
    </view>
    <!-- 购物车商品 -->
    <uni-swipe-action class="shop-cart-box">
      <block v-for="(item1,index1) in cart" :key='index1'>
        <uni-swipe-action-item :right-options="options" @click="removeById(item1)">
          <my-goods @change-redio="redioChangeHandler" :goods="item1" :show-redio="true" :show-num="true" @num-change="numChange"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
  <!-- 结算区 -->
    <my-settle></my-settle>
  </view>
</template> 

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    mixins: [badgeMix],
    computed: {
      ...mapState('my_cart', ['cart'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#C00000'
          }
        }]
      };
    },
    methods: {
      removeById(item1){
        this.removeGoodsById(item1.goods_id)
      },
      // ...mapMutations('my_cart',['updateGoodsCount']),
      numChange(e) {
        this.updateGoodsCount(e)
      },
      ...mapMutations('my_cart', ['updateGoodsState', 'updateGoodsCount','removeGoodsById']),
      redioChangeHandler(e) {
        this.updateGoodsState(e)
      }
    }
  }
</script>

<style lang="scss">
  .null-box {
    display: flex;
    flex-direction: column;
    // justify-content: space-around;
    margin-top: 250rpx;
    align-items: center;
    image {
      width: 300rpx;
      height: 300rpx;
    }
    text {
      margin-top: 50rpx;
    }
  }
  .shop-cart-box {
    padding-bottom: 100rpx;
  }
  // 标题样式
  .title-box {
    display: flex;
    align-items: center;

    .shop-icon {}

    .title-text {}
  }
</style>
